package com.jin.webvideo.externalInterfaces.video;

import com.jin.webvideo.exception.UnavailableServiceException;
import com.jin.webvideo.exception.UnsupportServiceException;
import com.jin.webvideo.externalInterfaces.PlatformSupport;
import com.jin.webvideo.externalInterfaces.entity.Filmography;
import com.jin.webvideo.externalInterfaces.entity.FilmographyInfo;

import com.jin.webvideo.externalInterfaces.iqiyi.IQIYIVideoInfoHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import java.io.IOException;
import java.util.List;
@Component
public class IQIYIApi extends AbstractVideoAPI{
    @Autowired
    private IQIYIVideoInfoHandler videoInfoHandler;

    @Override
    public Filmography baseInfo(String docid, String tvid) throws UnavailableServiceException {
        try {
            return videoInfoHandler.baseInfo(docid, tvid);
        } catch (IOException e) {
            e.printStackTrace();
            throw new UnsupportServiceException();
        }
    }

    @Override
    public List<FilmographyInfo> videoInfoList(String docid, String tvid, Integer pageNo, Integer pageSize) throws UnavailableServiceException {
        try {
            return videoInfoHandler.videoInfos(docid, tvid, String.valueOf(pageSize), String.valueOf(pageNo));
        } catch (Exception e) {
            e.printStackTrace();
            throw new UnsupportServiceException();
        }
    }

    @Override
    String platformName() {
        return PlatformSupport.PLATFORM_IQIYI;
    }
}
